﻿using PermissionManager.BLL;
using PermissionManager.Model;
using PermissionManager.Models;
using PermissionsManager.Models;
using System;
using System.Collections.Generic;
using System.Web.Mvc;

namespace PermissionManager.Controllers
{
    public class MenuController : Controller
    {
        // GET: M
        private MenuService menuService = new MenuService();
        private Opretation opretation = new Opretation();
        // GET: System
        public ActionResult MenuSection()
        {
            List<Menu> menu = menuService.QueryList(a=>true);
            if (menu!=null)
            {
                ViewBag.list = menu;
            }
            return View();
        }
        /// <summary>
        /// 获取菜单信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public JsonResult GetMenu(int page, int limit)
        {
            int count = 0;
            List<Menu> menus = menuService.QueryPageList(page, limit, a => a.Id != 0, a => a.Id);
            GetJsonToTable<Menu> getJson = new GetJsonToTable<Menu>()
            {
                msg = "",
                code = 0,
                count = menuService.GetCount(a => a.Id != 0, out count),
                data = menus
            };
            return Json(getJson, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <returns></returns>
        public JsonResult UpdateIsShow(Menu menu)
        {
            opretation.Success = menuService.UpdateIsshow(menu);
            return Json(opretation);
        }
        public JsonResult AddMenuInfo(Menu menu)
        {
            menu.CreateUserId = AdminUserContext.context.UserInfo_no.Id;
            menu.CreateTime = DateTime.Now;
            opretation.Success = menuService.Add(menu);
            return Json(opretation);
        }
        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public JsonResult UpdateMenuInfo(Menu menu)
        {
            opretation.Success = menuService.UpdateMenu(menu);
            return Json(opretation);
        }
        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public JsonResult DeleteMenuInfo(Menu menu)
        {
            opretation.Success = menuService.Delete(menu);
            return Json(opretation);
        }
    }
}